Skip to content

Method: hasChanges(Object, Object)

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.sessions.change;
16:
17: import cz.cvut.kbss.jopa.sessions.MetamodelProvider;
18:
19: import java.util.Collection;
20: import java.util.Map;
21:
22: class ChangeDetectors implements ChangeDetector {
23:
24: private static final ChangeDetector MANAGED_TYPE_DETECTOR = new ManagedTypeChangeDetector();
25:
26: private final MetamodelProvider metamodelProvider;
27:
28: private final ChangeDetector mapChangeDetector;
29: private final ChangeDetector collectionChangeDetector;
30:
31: ChangeDetectors(MetamodelProvider metamodelProvider, ChangeManagerImpl changeManager) {
32: this.metamodelProvider = metamodelProvider;
33: this.mapChangeDetector = new MapChangeDetector(this, changeManager);
34: this.collectionChangeDetector = new CollectionChangeDetector(this, changeManager, metamodelProvider);
35: }
36:
37: @Override
38: public Changed hasChanges(Object clone, Object original) {
39:• if ((clone == null && original != null) || (clone != null && original == null)) {
40: return Changed.TRUE;
41: }
42:• if (clone == null) {
43: return Changed.FALSE;
44: }
45:
46:• if (metamodelProvider.isTypeManaged(clone.getClass())) {
47: return MANAGED_TYPE_DETECTOR.hasChanges(clone, original);
48:• } else if (clone instanceof Collection) {
49: return collectionChangeDetector.hasChanges(clone, original);
50:• } else if (clone instanceof Map) {
51: return mapChangeDetector.hasChanges(clone, original);
52: }
53:• return Changed.fromBoolean(!clone.equals(original));
54: }
55:
56: private static class ManagedTypeChangeDetector implements ChangeDetector {
57:
58: @Override
59: public Changed hasChanges(Object clone, Object original) {
60: return Changed.UNDETERMINED;
61: }
62: }
63: }